import absorbRectPos from '../service/absorbpossvc/absorbonrectpos.js'
import absorbCirclePos from '../service/absorbpossvc/absorboncirclepos.js'
import absorbMultiPos from '../service/absorbpossvc/absorbonmultipos.js'
import absorbArcPos from '../service/absorbpossvc/absorbonarcpos.js'
import absorbPointPos from '../service/absorbpossvc/absorbonpointpos.js'
import absorbonpathcoordpos from './absorbpossvc/absorbonpathcoordpos.js'
import absorbcubepos from './absorbpossvc/absorbcubepos.js'
import absorbcylinder from './absorbpossvc/absorbcylinder.js'

import  {LGXEnums}  from '../common/sysenum.js'
var posMode = LGXEnums.LGXPosMode;
var GraphTypeEnums = LGXEnums.LGXGraphType;

var AbsorbPosSvc = {}

AbsorbPosSvc.calculate = function (mousePt, destPos, scaling) {
    var pt = null;
    if (destPos.posType == posMode.circle_mode) {
        pt = absorbCirclePos.AbsorbCirclePos.calculate(mousePt, destPos);
    }
    else if (destPos.posType == posMode.rect_mode) {
        pt = absorbRectPos.AbsorbRectPos.calculate(mousePt, destPos);
    }
    else if (destPos.posType == posMode.multiPt_Mode) {
        pt = absorbMultiPos.AbsorbMultiPos.calculate(mousePt, destPos);
    }
    else if (destPos.posType == posMode.arc_mode) {
        pt = absorbArcPos.AbsorbArcPos.calculate(mousePt, destPos);
    }
    else if (destPos.posType == posMode.point_mode) {
        pt = absorbPointPos.AbsorbPointPos.calculate(mousePt, destPos);
    }
    else if (destPos.posType == posMode.pathLinke_mode) {
        pt = absorbonpathcoordpos.AbsorbOnPathCoordPos.calculate(mousePt, destPos);
    }
    else if (destPos.posType == posMode.hatch_mode) {
        pt = absorbonpathcoordpos.AbsorbOnPathCoordPos.calculate(mousePt, destPos);
    }
    return pt;
}

AbsorbPosSvc.calculateOnGraph = function (pDstGraph, offsetPt, mousePt, scaling) {
    var pt = null;
    let mutliPointFlag = false;
    let absorbSvc = null;
    let complexBaseUnit = false;//立方体、圆柱、带切角矩形这些都是复杂基本图元

    switch (pDstGraph.m_graphType) {
        case GraphTypeEnums.CircleGraph_type:
            absorbSvc = absorbCirclePos.AbsorbCirclePos;
            break;

        case GraphTypeEnums.RectGraph_type:
            absorbSvc = absorbRectPos.AbsorbRectPos;
            break;

        case GraphTypeEnums.PolygonGraph_type:
        case GraphTypeEnums.LineGraph_type:
        case GraphTypeEnums.RegularPolygon_type:
        case GraphTypeEnums.MultiStar_type:
            absorbSvc = absorbMultiPos.AbsorbMultiPos;
            mutliPointFlag = true;
            break;

        case GraphTypeEnums.ArcGraph_type:
            absorbSvc = absorbArcPos.AbsorbArcPos;
            break;

        case GraphTypeEnums.Path_type:
            absorbSvc = absorbonpathcoordpos.AbsorbOnPathCoordPos;
            break;

        case GraphTypeEnums.Cube_type:
            complexBaseUnit = true;
            absorbSvc = absorbcubepos.AbsorCubePos;
            break;

        case GraphTypeEnums.Cylinder_type:
            complexBaseUnit = true;
            absorbSvc = absorbcylinder.AbsorCylinderPos;
            break;
    }

    if (absorbSvc) {
        if (!complexBaseUnit) {
            let graphPos = pDstGraph.getPosCopy();
            var destPos = graphPos;
            if (offsetPt) {
                destPos = graphPos.createCopyPos(offsetPt);
            }
            if (mutliPointFlag && pDstGraph.chkClose()){
                destPos.addPoint(destPos.posList[0]);
            }
            pt = absorbSvc.calculate(mousePt, destPos);
        }
        else {
            pt = absorbSvc.calculate(pDstGraph, mousePt, offsetPt);
        }
    }
    return pt;
}



export default { AbsorbPosSvc }